//
//  UIBarbuttonItem+Extension.swift
//  YQL_WeiBo
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit


extension UIBarButtonItem{
    
    
    convenience init(title: String = "", imageName: String = "", target: Any?, action: Selector?) {
        
        self.init()
        //创建按钮
        let button = UIButton()
        //设置按钮图片
        button.setImage(UIImage.init(named: imageName), for: .normal)
        button.setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
        //设置文字颜色字体大小
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        //按钮自适应大小
        button.sizeToFit()
        //添加点击事件
        if let ac = action {
            button.addTarget(target, action: ac, for: .touchUpInside)
        }
        //设置button为UIBarButtonItem的customView
        self.customView = button
        
    }
    
    
    
    
    
}
